<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <button @click="num1 = 30">点击修改数值</button>
        <h3>{{reducerNum}}</h3>
        <br><hr>
        <button @click="putNum = {num1:88,num2:66,num3:33}">点击修改数值</button>
        <h3>{{putNum}}</h3>
    </div>
    <script>
        const vm = new Vue({
            data(){
                return{
                    fullNum : null,
                    num1: 10,
                    num2: 20,
                    num3: 30
                }
            },
            computed:{
                reducerNum(){
                    return this.num1 + this.num2 + this.num3
                },
                putNum:{
                    get(){ //读取时触发
                        return this.num1 + this.num2 + this.num3
                    },
                    set (val){ //设置时触发
                        this.num1 = val.num1,
                        this.num2 = val.num2,
                        this.num3 = val.num3                    
                    }
                }
            }
        }).$mount("#app")
    </script>
</body>

</html>